package com.test.designPattern.structuralType.flyweightPattern;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 工具箱
 *
 * @author wangjie
 * @version V1.0
 * @date 2020/4/7
 */
@Slf4j
public class Tools {

    private static ConcurrentHashMap<String, Tool> tools = new ConcurrentHashMap<>();

    public Tool getCaeKey(String key){

        if(!tools.contains(key)){
            log.info("工具箱里没有这个，得先买一个");
            tools.put(key,new ToolImpl(key));
            log.info("买好了，放进工具箱");
        }

        return tools.get(key);
    }
}
